package cn.wolfcode.web.controller;

import cn.wolfcode.Condition;
import cn.wolfcode.common.web.Result;
import cn.wolfcode.common.web.anno.RequireLogin;
import cn.wolfcode.domain.OrderInfo;
import cn.wolfcode.domain.Product;
import cn.wolfcode.service.IProductService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/product")
@Slf4j
@RequireLogin
public class ProductController {
    private final IProductService productService;

    public ProductController(IProductService productService) {
        this.productService = productService;
    }

//    @RequestMapping("/selectByIdList")
//    public Result<List<Product>> selectByIdList(@RequestParam("ids") List<Long> idList) {
//        return Result.success(productService.selectByIdList(idList));
//    }
    @PostMapping("/addOrder")
    public Result<?> addOrderFeign(@RequestBody OrderInfo orderInfo){
        productService.addOrder(orderInfo);
        return Result.success();
    }
    @GetMapping("/findAll")
    public Result<List<Product>> findAll() {
        return Result.success(productService.findAll());
    }
    @GetMapping("/findById")
    public Result<Product> findById(Long id) {
        return Result.success(productService.findById(id));
    }
    @PostMapping("/conditionFindByPage")
    public Result<PageInfo<OrderInfo>> conditionFindByPage(@RequestParam("page") Integer page,
                                                          @RequestParam("pageSize") Integer pageSize,
                                                          @RequestBody Condition condition) {
        return Result.success(productService.conditionFindByPage(page, pageSize, condition));
    }

    @PostMapping("/updateOrder")
    public Result<?> updateOrder(@RequestBody OrderInfo orderInfo) {
        productService.updateOrder(orderInfo);
        return Result.success();
    }
    @PostMapping("/batchDeleteOrder")
    public Result<?> batchDeleteOrder(@RequestBody List<Long> ids) {
        productService.batchDeleteOrder(ids);
        return Result.success();
    }

}
